home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / xlib04.zip / XDETECT.ASM < prev    next >
Assembly Source File  |  1992-11-12  |  7KB  |  238 lines

  1. ;-----------------------------------------------------------------------
  2. ; MODULE XDETECT
  3. ;
  4. ; Hardware detection module
  5. ;
  6. ; Compile with Tasm.
  7. ; C callable.
  8. ;
  9. ;
  10. ; ****** XLIB - Mode X graphics library                ****************
  11. ; ******                                               ****************
  12. ; ****** Written By Themie Gouthas                     ****************
  13. ;
  14. ; egg@dstos3.dsto.gov.au
  15. ; teg@bart.dsto.gov.au
  16. ;-----------------------------------------------------------------------
  17. LOCALS
  18. .286
  19.  
  20. include model.inc
  21. include xdetect.inc
  22.  
  23.     .data
  24.  
  25. _MouseButtonCount dw 0
  26. _MouseVersion     dw 0
  27. _MouseType        db 0
  28. _MouseIRQ         db 0
  29.  
  30.     .code
  31.  
  32.  
  33. i86       equ 0
  34. i186      equ 1
  35. i286      equ 2
  36. i386      equ 3
  37.  
  38.  
  39. NONE      equ 0
  40. MDA       equ 1
  41. CGA       equ 2
  42. EGAMono   equ 3
  43. EGAColor  equ 4
  44. VGAMono   equ 5
  45. VGAColor  equ 6
  46. MCGAMono  equ 7
  47. MCGAColor equ 8
  48.  
  49. PS2_CARDS db  0,1,2,2,4,3,2,5,6,2,8,7,8
  50.  
  51.  
  52. ;-----------------------------------------------------------------------
  53. ; PC Graphics detection routine. Returns graphics card type
  54. ;
  55. ; C callable as:
  56. ;    unsigned int x_graphics_card();
  57. ;
  58. ;
  59.  
  60. proc _x_graphics_card
  61.     push bp                  ; Preserve caller's stack frame
  62.     mov  bp,sp
  63.     mov  ax,1A00h            ; Try calling VGA Identity Adapter function
  64.     int  10h
  65.     cmp  al,1Ah              ; Do we have PS/2 video bios ?
  66.     jne  @@not_PS2           ; No!
  67.  
  68.     cmp  bl,0Ch              ; bl > 0Ch => CGA hardware
  69.     jg   @@is_CGA            ; Jump if we have CGA
  70.     xor  bh,bh
  71.     xor  ah,ah
  72.     mov  al,cs:PS2_CARDS[bx] ; Load ax from PS/2 hardware table
  73.     jmp  short @@done        ; return ax
  74. @@is_CGA:
  75.     mov  ax,CGA              ; Have detected CGA, return id
  76.     jmp  short @@done
  77. @@not_PS2:                       ; OK We don't have PS/2 Video bios
  78.     mov  ah,12h              ; Set alternate function service
  79.     mov  bx,10h              ; Set to return EGA information
  80.     int  10h                 ; call video service
  81.     cmp  bx,10h              ; Is EGA there ?
  82.     je   @@simple_adapter    ; Nop!
  83.     mov  ah,12h              ; Since we have EGA bios, get details
  84.     mov  bl,10h
  85.     int  10h
  86.     or   bh,bh               ; Do we have colour EGA ?
  87.     jz   @@ega_color         ; Yes
  88.     mov  ax,EGAMono          ; Otherwise we have Mono EGA
  89.     jmp  short @@done
  90. @@ega_color:
  91.     mov  ax,EGAColor         ; Have detected EGA Color, return id
  92.     jmp  short @@done
  93. @@simple_adapter:
  94.     int  11h                 ; Lets try equipment determination service
  95.     and  al,30h
  96.     shr  al,4
  97.     xor  ah,ah
  98.     or   al,al               ; Do we have any graphics card at all ?
  99.     jz   @@done              ; No ? This is a stupid machine!
  100.     cmp  al,3                ; Do We have a Mono adapter
  101.     jne  @@is_CGA            ; No
  102.     mov  ax,MDA              ; Have detected MDA, return id
  103. @@done:
  104.     pop  bp                  ;restore caller's stack frame
  105.     ret
  106. _x_graphics_card endp
  107.  
  108.  
  109. ;-----------------------------------------------------------------------
  110. ; PC Processor detection routine
  111. ;
  112. ; C callable as:
  113. ;    unsigned int x_processor();
  114. ;
  115. ;
  116. proc _x_processor
  117.     push bp
  118.     mov  bp,sp
  119.     pushf                    ; Save flags
  120.     xor  ax,ax         ; Clear AX
  121.     push ax                  ; Push it on the stack
  122.     popf                     ; Zero the flags
  123.     pushf                    ; Try to zero bits 12-15
  124.     pop  ax                  ; Recover flags
  125.         and  ax,0F000h           ; If bits 12-15 are 1 => i86 or i286
  126.         cmp  ax,0F000h
  127.         jz   is_86_186
  128.  
  129.         mov  ax,07000h           ; Try to set bits 12-14
  130.         push ax
  131.         popf
  132.         pushf
  133.         pop  ax
  134.         and  ax,07000h           ; If bits 12-14 are 0 => i286
  135.         jz   is_286
  136.  
  137.         mov  ax,i386             ; We have a 386
  138.         jmp  short @@done
  139.  
  140. is_286:
  141.         mov  ax,i286             ; We have a 286
  142.         jmp  short @@done
  143.  
  144. is_86_186:                       ; Determine whether i86 or i186
  145.         push cx                  ; save CX
  146.         mov  ax,0FFFFh           ; Set all AX bits
  147.         mov  cl,33               ; Will shift once on 80186
  148.         shl  ax,cl               ; or 33 x on 8086
  149.         pop  cx
  150.         jnz  is_186              ; 0 => 8086/8088
  151. is_86:
  152.         mov  ax,i86
  153.         jmp  short @@done
  154. is_186:
  155.         mov  ax,i186
  156. @@done:
  157.     popf
  158.     pop  bp
  159.     ret
  160. _x_processor endp
  161.  
  162. .8086
  163. ;-----------------------------------------------------------------------
  164. ; PC Numeric coprocessor detection routine
  165. ;
  166. ; C callable as:
  167. ;    unsigned int x_coprocessor();
  168. ;
  169. ;  Based on an article in PC Tech Journal, Aug 87 by Ted Forgeron
  170. ;
  171. ;  Returns 1 if coprocessor found, zero otherwise
  172.  
  173. _x_coprocessor   proc
  174. ARG     control:word=StkSize
  175.     push   bp
  176.     mov    bp,sp
  177.     sub    sp,StkSize
  178.  
  179.     fninit                          ; try to initialize the copro.
  180.     mov    [control],0              ; clear control word variable
  181.         fnstcw control                  ; put control word in memory
  182.     mov    ax,[control]             ;
  183.     cmp    ah,03h                   ; do we have a coprocessor ?
  184.     je     @@HaveCopro              ; jump if yes!
  185.     xor    ax,ax                    ; return 0 since nothing found
  186.     jmp    short @@Done
  187. @@HaveCopro:
  188.     mov    ax,1
  189. @@Done:
  190.     mov    sp,bp
  191.     pop    bp
  192.     ret
  193. _x_coprocessor   endp
  194.  
  195.  
  196. ;-----------------------------------------------------------------------
  197. ; PC Mouse Driver detection routine
  198. ;
  199. ; C callable as:
  200. ;    unsigned int x_mousedriver();
  201. ;
  202. ;
  203. ;  Returns 1 if mouse driver found, zero otherwise
  204. _x_mousedriver proc
  205.            push bp
  206.            mov  bp,sp
  207.            mov  ax,3533h        ; Get int 33 interrupt vector
  208.            int  21h             ; Call dos
  209.            xor  cx,cx           ; Clear "found" flag
  210.            mov  ax,es           ; Is the vector null (ES==0 && BX==0) ?
  211.            or   bx,ax
  212.            jz   @@NoMouseDriver ; Yes! No mouse driver installed - Jump
  213.  
  214.            ; Just make absolutely sure the vector points to the mouse
  215.            ; driver (just in case)
  216.  
  217.            xor  ax,ax           ; FUNC 0: Mouse Initialization
  218.            int   33h
  219.            or    ax,ax          ; Do we have an installed mouse driver ?
  220.            jz    @@NoMouseDriver; No ?
  221.            mov   [_MouseButtonCount],bx
  222.  
  223.            mov   ax,24h
  224.            int   33h
  225.            mov   [_MouseVersion],bx
  226.            mov   [_MouseType],ch
  227.            mov   [_MouseIRQ],cl
  228.  
  229.            mov  cx,1            ; Yes! set flag
  230.  
  231. @@NoMouseDriver:
  232.            mov  ax,cx           ; Return "found" flag
  233.            pop  bp
  234.            ret
  235. _x_mousedriver endp
  236.  
  237.  
  238. end